﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

public sealed class SmartDataReaderSQL
{
    private DateTime defaultDate;
    private SqlDataReader reader;

    public SmartDataReaderSQL(SqlDataReader reader)
    {
        this.defaultDate = DateTime.MinValue;
        this.reader = reader;
    }

    public int GetInt32(String column)
    {
        int data = (reader.IsDBNull(reader.GetOrdinal(column)))
                                ? (int)0 : (int)reader[column];
        return data;
    }

    public int GetInt32(int column)
    {
        int data = (reader.IsDBNull(column))
                                ? (int)0 : (int)reader.GetInt32(column);
        return data;
    }

    public short GetInt16(String column)
    {
        short data = (reader.IsDBNull(reader.GetOrdinal(column)))
                              ? (short)0 : (short)reader[column];
        return data;
    }

    public short GetInt16(int column)
    {
        short data = (reader.IsDBNull(column))
                              ? (short)0 : (short)reader.GetInt16(column);
        return data;
    }

    public float GetFloat(String column)
    {
        float data = (reader.IsDBNull(reader.GetOrdinal(column)))
                    ? 0 : float.Parse(reader[column].ToString());
        return data;
    }

    public float GetFloat(int column)
    {
        float data = (reader.IsDBNull(column))
                    ? 0 : reader.GetFloat(column);
        return data;
    }

    public double GetDouble(String column)
    {
        double data = (reader.IsDBNull(reader.GetOrdinal(column)))
                    ? 0 : double.Parse(reader[column].ToString());
        return data;
    }

    public double GetDouble(int column)
    {
        double data = (reader.IsDBNull(column))
                    ? 0 : reader.GetDouble(column);
        return data;
    }

    public bool GetBoolean(String column)
    {
        bool data = (reader.IsDBNull(reader.GetOrdinal(column)))
                                 ? false : (bool)reader[column];
        return data;
    }

    public bool GetBoolean(int column)
    {
        bool data = (reader.IsDBNull(column))
                                 ? false : (bool)reader.GetBoolean(column);
        return data;
    }

    public String GetString(String column)
    {
        String data = (reader.IsDBNull(reader.GetOrdinal(column)))
                               ? "" : reader[column].ToString();
        return data;
    }

    public String GetString(int column)
    {
        String data = (reader.IsDBNull(column))
                               ? "" : reader.GetString(column).ToString();
        return data;
    }

    public DateTime GetDateTime(String column)
    {
        DateTime data = (reader.IsDBNull(reader.GetOrdinal(column)))
                           ? defaultDate : (DateTime)reader[column];
        return data;
    }

    public DateTime GetDateTime(int column)
    {
        DateTime data = (reader.IsDBNull(column))
                           ? defaultDate : (DateTime)reader.GetDateTime(column);
        return data;
    }

    public byte[] GetByteArray(String column)
    {
        byte[] data = (reader.IsDBNull(reader.GetOrdinal(column)))
                           ? new byte[0] : (byte[])reader[column];
        return data;
    }

    public bool Read()
    {
        return this.reader.Read();
    }

}